package cn.fy.location.activity;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.database.ContentObserver;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.telephony.SmsMessage;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;

import cn.fy.location.databinding.ActivitySmsBinding;

public class SmsActivity extends AppCompatActivity {

    private ActivitySmsBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.activity_sms);
        binding = ActivitySmsBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setTitle("拨打电话 发送短信");

        binding.btnDialPhone.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(); //创建Intent对象
                intent.setAction(intent.ACTION_DIAL); //调用拨号面板
                intent.setData(Uri.parse("tel:043184978981")); //设置要拨打的号码
                startActivity(intent); //启动Activity
            }
        });

        binding.btnSendMsg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(); //创建Intent对象
                intent.setAction(intent.ACTION_SENDTO); //调用发送短信息
                intent.setData(Uri.parse("smsto:5554")); //设置要发送的号码,5554模拟器发送的号码
                intent.putExtra("sms_body", "Welcome to Android!"); //设置要发送的信息内容
                startActivity(intent); //启动Activity
            }
        });
    }

    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {

        switch (item.getItemId()) {
            case android.R.id.home:
                finish();
                break;
            default:
                break;
        }
        return super.onOptionsItemSelected(item);
    }

}